<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>生产派工单</title>
    <link rel="shortcut icon" href="favicon.ico">
    <link href="/css/bootstrap.min.css?v=3.3.6" rel="stylesheet">
    <link href="/css/font-awesome.min.css?v=4.4.0" rel="stylesheet">
    <link href="/css/animate.css" rel="stylesheet">
    <link href="/css/style.css?v=4.1.0" rel="stylesheet">
    <link href="/bootstraptable/bootstrap-table.css" rel="stylesheet">
</head>
<body>
<div style="color: #0e9aef;margin: 20px;">您正在做的业务是：生产管理--生产调度管理--制定生产派工单</div>

<div class="container" id="send_work_div">
    <div style="text-align: right">
        <button class="btn btn-default" id="sub_btn">提交</button>
        <button class="btn btn-default" onclick="javascript:history.back()">返回</button>
    </div>

    <div class="panel panel-default" style="margin-top: 10px;">
        <form class="form-horizontal" id="send_work_order_form">
            <div>
                    <h3 style="margin-top: 30px;text-align: center;">生产派工单</h3>
            </div>
            <div class="panel-body">
                <div class="form-group">
                    <div class="col-md-6">
                        <label class="col-md-4 control-label">工单制定人：</label>
                        <div class="col-md-8">
                            <input type="text" class="form-control" name="designer" id="designer" style="border: none;border-bottom: 1px solid black" />
                        </div>
                    </div>
                    <div class="col-md-6">
                        <label class="col-md-4 control-label">出库单编号：</label>
                        <div class="col-md-8">
                            <input type="text" class="form-control" name="manufactureId" id="manufactureId" style="border: none;border-bottom: 1px solid black" />
                        </div>
                    </div>
                </div>
                <div class="form-group">
                    <div class="col-md-6">
                        <label class="col-md-4 control-label">产品编号：</label>
                        <div class="col-md-8">
                            <input type="text" class="form-control" name="productId" id="productId" style="border: none; background-color: white" readonly />
                        </div>
                    </div>
                    <div class="col-md-6">
                        <label class="col-md-4 control-label">产品名称：</label>
                        <div class="col-md-8">
                            <input type="text" class="form-control" name="productName" id="productName" style="border: none; background-color: white" readonly />
                        </div>
                    </div>
                </div>
                <div class="form-group">
                    <div class="col-md-6">
                        <label class="col-md-4 control-label">数量：</label>
                        <div class="col-md-8">
                            <input type="text" class="form-control" name="amount" id="amount" style="border: none; background-color: white" readonly />
                        </div>
                    </div>
                    <div class="col-md-6">
                        <label class="col-md-4 control-label">描述：</label>
                        <div class="col-md-8">
                            <input type="text" class="form-control" name="productDescribe" id="productDescribe" style="border: none; background-color: white" readonly />
                        </div>
                    </div>
                </div>

                <table id="send_work_order_table"></table>

                <div class="form-group" style="margin-top: 10px;">
                    <div class="col-md-6">
                        <label class="col-md-4 control-label">登记人：</label>
                        <div class="col-md-8">
                            <input type="text" name="register" id="register" style="border: none;border-bottom: 1px solid black" />
                        </div>
                    </div>
                    <div class="col-md-6">
                        <label class="col-md-4 control-label">登记时间：</label>
                        <div class="col-md-8">
                            <input type="text" class="form-control" name="registerTime" id="registerTime" style="border: none; background-color: white" readonly />
                        </div>
                    </div>
                </div>
                <div class="form-group">
                    <div class="col-md-12">
                        <label class="col-md-2 control-label">备注：</label>
                        <div class="col-md-8">
                            <textarea cols="50" rows="3" class="form-control" style="resize: none;" id="remark" name="remark"></textarea>
                        </div>
                    </div>
                </div>
            </div>
        </form>
    </div>
</div>


<div class="modal fade" id="send_work_modal">
    <div class="modal-dialog modal-lg">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal">
                    <span onclick="clearInfo()">&times;</span>
                </button>
            </div>
            <div class="modal-body">
                <div class="panel panel-default">
                    <div class="panel-heading" style="background-color: white">
                        <div class="panel-title">
                            <h3 style="margin-top: 30px;text-align: center;">生产派工单</h3>
                        </div>
                    </div>
                    <div class="panel-body">
                        <form class="form-horizontal">
                            <div class="form-group">
                                <div class="col-md-6">
                                    <label class="control-label col-md-4">设计单编号：</label>
                                    <div class="col-md-8">
                                        <input type="text" class="form-control" readonly name="designId" id="designId" style="border: none;background-color: white;">
                                    </div>
                                </div>
                                <div class="col-md-6">
                                    <label class="control-label col-md-4">工序名称：</label>
                                    <div class="col-md-8">
                                        <input type="text" class="form-control"  readonly name="procedureName" id="procedureName" style="border: none;background-color: white;">
                                    </div>
                                </div>
                            </div>
                           <table id="send_work_modal_table"></table>
                        </form>
                    </div>
                </div>

            </div>
            <div class="modal-footer">
                <button type="button" id="back_btn" class="btn btn-default col-md-2 col-md-offset-10">返回
                </button>
            </div>
        </div>
    </div>
</div>


<!-- 全局js -->
<script src="/js/jquery.min.js?v=2.1.4"></script>
<script src="/js/bootstrap.min.js?v=3.3.6"></script>
<script src="/js/plugins/metisMenu/jquery.metisMenu.js"></script>
<script src="/js/plugins/slimscroll/jquery.slimscroll.min.js"></script>
<script src="/js/plugins/layer/layer.min.js"></script>

<!-- 自定义js -->
<script src="/js/hAdmin.js?v=4.1.0"></script>
<script src="/js/currentTime.js"></script>

<!-- 第三方插件 -->
<script src="/js/plugins/pace/pace.min.js"></script>

<!--BootstrapTable-->
<script src="/bootstraptable/bootstrap-table.min.js"></script>
<script src="/bootstraptable/locale/bootstrap-table-zh-CN.min.js"></script>


<script>
    $(function (){
        let pid=localStorage.getItem("productId")
        let num=localStorage.getItem("amount")

        $("#send_work_order_form #registerTime").val(add(fortime()))

        $.post("/manufacture/apply/getProductIdQueryApply",{"pid":pid},function (res){
            $("#send_work_order_form #productId").val(res[0].productId)
            $("#send_work_order_form #productName").val(res[0].productName)
            $("#send_work_order_form #amount").val(num)
            $("#send_work_order_form #procedureDescribe").val(res[0].procedureDescribe)
        })


        $("#send_work_order_table").bootstrapTable({
            method: "post",
            contentType: "application/x-www-form-urlencoded",
            url: "/manufacture/process/getProductIdProcessDetails",
            // 数据行交替样式
            striped: true,
            // 是否是服务器端分页：server表示服务器端，client表示前端分页
            sidePagination: 'server',
            queryParams: function (params) {
                let obj = {
                   pid:pid
                }
                return obj;
            },
            // 表格列标题
            columns: [{
                title: "序号",
                field: "detailsNumber"
            }, {
                title: "工序名称",
                field: "procedureName"
            }, {
                title: "工序编号",
                field: "procedureId",
            }, {
                title: "描述",
                field: "procedureDescribe"
            }, {
                title: "工时数（小时）",
                field: "labourHourAmount",
                formatter:function (value,row,index){
                    return row.labourHourAmount=row.labourHourAmount*num
                }
            }, {
                title: "单位工时成本（元）",
                field: "costPrice",
            },{
                title: "工时成本小计（元）",
                field: "subtotal",
                formatter:function (value,row,index){
                    return row.subtotal=row.labourHourAmount*row.costPrice
                }
            },{
                title: "查看物料",
                field: "",
                formatter:function (value,row,index){
                    return `<a href="javascript:showProduct(${row.id},${row.labourHourAmount})">查看物料</a>`
                }
            }]
        })

        $("#send_work_div #sub_btn").click(function (){
            let data=$("#send_work_order_table").bootstrapTable("getData")
            let ary=JSON.parse(localStorage.getItem("id_ary"))
            let dto={
                designer:$("#send_work_order_form #designer").val(),
                productId:$("#send_work_order_form #productId").val(),
                productName:$("#send_work_order_form #productName").val(),
                amount:$("#send_work_order_form #amount").val(),
                register:$("#send_work_order_form #register").val(),
                registerTime:$("#send_work_order_form #registerTime").val(),
                remark:$("#send_work_order_form #remark").val(),
            }
            dto.ary=ary
            dto.details=data

            $.ajax({
                url:"/manufacture/detail/addManufactureDetails",
                type:"post",
                data:JSON.stringify(dto),
                contentType:"application/json",
                success: function (data) {
                    if(data){
                        window.location="create_production_dispatch_work_ordersUI"
                    }
                }
            })
        })

        //设置模态框的属性
        $("#send_work_modal").modal({
            backdrop: false,
            keyboard: false,
            show: false
        })

        $("#send_work_modal #back_btn").click(function (){
            $("#send_work_modal_table").bootstrapTable("destroy")
            $("#send_work_modal").modal("hide")
        })



    })

    function clearInfo(){
        $("#send_work_modal_table").bootstrapTable("destroy")
    }

    function showProduct(id,hour){
        $("#send_work_modal").modal("show")
        $.post("/manufacture/process/getIdQuery",{"id":id},function (res){
            console.log(res)
            $("#send_work_modal #procedureName").val(res[0])
            $("#send_work_modal #designId").val(res[1])
        })

        $("#send_work_modal_table").bootstrapTable({
            method: "post",
            contentType: "application/x-www-form-urlencoded",
            url: "/manufacture/process/getDetailsIdQueryProduct",
            // 数据行交替样式
            striped: true,
            // 是否是服务器端分页：server表示服务器端，client表示前端分页
            sidePagination: 'server',
            queryParams: function (params) {
                let obj = {
                    pid:id
                }
                return obj;
            },
            // 表格列标题
            columns: [{
                title: "序号",
                field: "detailsNumber"
            }, {
                title: "物料名称",
                field: "productName"
            }, {
                title: "物料编号",
                field: "productId",
            }, {
                title: "描述",
                field: "procedureDescribe"
            }, {
                title: "本工序数量",
                field: "amount",
                formatter:function (value,row,index) {
                    return row.amount=row.amount*hour
                }
            }, {
                title: "单位",
                field: "amountUnit",
            },{
                title: "单价（元）",
                field: "costPrice",

            },{
                title: "小计（元）",
                field: "subtotal",
                formatter:function (value,row,index) {
                    return row.subtotal=row.amount*row.costPrice
                }
            }]
        })
    }
</script>
</body>
</html>